# Generate lines

import numpy as np
import sys

if __name__=='__main__':

    try:
        nx = int(sys.argv[1])
    except:
        print 'usage: genklines.py <number of points>'
        sys.exit()
        
    kG = np.array([0,0,0]);
    kX = np.array([1.0,0,0]);
    kL = np.array([0.5,0.5,0.5]);
    
    kW = np.array([1.0,0.5,0]);
    kK = np.array([0.75,0.75,0.0]);
    kU = np.array([1.0,0.25,0.25]);

    nseg = 3;
    x = np.linspace(0,1.0,nx);


    #seg = (kL,kG,kK)

    seg = (kL*0.25/np.linalg.norm(kL),kG,kK*0.25/np.linalg.norm(kW))

    ix = []
    for j in range(0,len(seg)-1):
        for i in range(0,nx):
            ix.append([i,j])
            v = seg[j+1] * x[i] + seg[j] * (1-x[i])
            if (i==0 and j==0):
                k = v
            else:
                k = np.vstack((k,v))

    ix = np.array(ix)

    data = np.hstack((k,ix))
    
    np.savetxt('kfile.dat',data)
    print k.shape
